package testes;

import static org.junit.Assert.*;

import org.bunny.businessLayer.CalendarDate;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class CalendarDateTest {

	protected CalendarDate d1 = new CalendarDate();
	protected CalendarDate d2= new CalendarDate();
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
		d1.setDay(1);
		d1.setMonth(3);
		d1.setYear(1990);
		
		d2.setDay(30);
		d2.setMonth(4);
		d2.setYear(2012);
		
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testCalendarDate() {
		CalendarDate a = new CalendarDate();
		assertNotNull(a);
		assertTrue(CalendarDate.allInstances.contains(a));
	}

	@Test
	public void testCalendarDateIntIntInt() {
		CalendarDate a = new CalendarDate(2,3,1990);
		assertNotNull(a);
		assertTrue(CalendarDate.allInstances.contains(a));
		assertEquals(2,a.day());
		assertEquals(3,a.month());
		assertEquals(1990,a.year());
		
		a.setDay(10);
		assertEquals(10,a.day());
		
		a.setMonth(6);
		assertEquals(6,a.month());
		
		a.setYear(2012);
		assertEquals(2012,a.year());
	}

	@Test
	public void testDestroy() {
		CalendarDate a = new CalendarDate();
		a.destroy();
		
		assertFalse(CalendarDate.allInstances.contains(a));
	}

	

	@Test
	public void testAdicionaDia() {
		d1.adicionaDia();
		assertEquals(2,d1.day());
		
		CalendarDate ult_dia_ano = new CalendarDate(31,12,2000);
		ult_dia_ano.adicionaDia();
		assertEquals(1,ult_dia_ano.day());
		assertEquals(1,ult_dia_ano.month());
		assertEquals(2001,ult_dia_ano.year());
		
		
		CalendarDate fev = new CalendarDate(28,2,2000);
		fev.adicionaDia();
		assertEquals(1,fev.day());
		assertEquals(3,fev.month());
		
		
		CalendarDate fev2 = new CalendarDate(27,2,2000);
		fev2.adicionaDia();
		assertEquals(28,fev2.day());
		assertEquals(2,fev2.month());
		
		CalendarDate d5 = new CalendarDate(28,12,2000);
		d5.adicionaDia();
		assertEquals(29,d5.day());
		assertEquals(12,d5.month());
		
		CalendarDate trintaum1 = new CalendarDate(31,1,2000);
		trintaum1.adicionaDia();
		assertEquals(1,trintaum1.day());
		assertEquals(2,trintaum1.month());
		
		CalendarDate trintaum2 = new CalendarDate(31,3,2000);
		trintaum2.adicionaDia();
		assertEquals(1,trintaum2.day());
		assertEquals(4,trintaum2.month());
		
		CalendarDate trintaum3 = new CalendarDate(31,5,2000);
		trintaum3.adicionaDia();
		assertEquals(1,trintaum3.day());
		assertEquals(6,trintaum3.month());
		
		CalendarDate trintaum4 = new CalendarDate(31,7,2000);
		trintaum4.adicionaDia();
		assertEquals(1,trintaum4.day());
		assertEquals(8,trintaum4.month());
		
		
		CalendarDate trintaum5 = new CalendarDate(31,8,2000);
		trintaum5.adicionaDia();
		assertEquals(1,trintaum5.day());
		assertEquals(9,trintaum5.month());
		
		CalendarDate trintaum6 = new CalendarDate(31,10,2000);
		trintaum6.adicionaDia();
		assertEquals(1,trintaum6.day());
		assertEquals(11,trintaum6.month());
		
		CalendarDate trintaum7 = new CalendarDate(31,12,2000);
		trintaum7.adicionaDia();
		assertEquals(1,trintaum7.day());
		assertEquals(1,trintaum7.month());
		assertEquals(2001,trintaum7.year());
		
		CalendarDate trinta7 = new CalendarDate(30,4,2000);
		trinta7.adicionaDia();
		assertEquals(1,trinta7.day());
		assertEquals(5,trinta7.month());
		
		CalendarDate trinta74 = new CalendarDate(30,6,2000);
		trinta74.adicionaDia();
		assertEquals(1,trinta74.day());
		assertEquals(7,trinta74.month());
		
		CalendarDate trinta75 = new CalendarDate(30,9,2000);
		trinta75.adicionaDia();
		assertEquals(1,trinta75.day());
		assertEquals(10,trinta75.month());
		
		CalendarDate trinta71 = new CalendarDate(30,1,2000);
		trinta71.adicionaDia();
		assertEquals(31,trinta71.day());
		assertEquals(1,trinta71.month());
		
		CalendarDate trinta7145 = new CalendarDate(30,11,2000);
		trinta7145.adicionaDia();
		assertEquals(1,trinta7145.day());
		assertEquals(12,trinta7145.month());
		
		CalendarDate trinta56 = new CalendarDate(30,5,2000);
		trinta56.adicionaDia();
		assertEquals(31,trinta56.day());
		assertEquals(5,trinta56.month());
		
		CalendarDate trinta546 = new CalendarDate(3,4,2000);
		trinta546.adicionaDia();
		assertEquals(4,trinta546.day());
		assertEquals(4,trinta546.month());
		
		CalendarDate trinta5463 = new CalendarDate(3,6,2000);
		trinta5463.adicionaDia();
		assertEquals(4,trinta5463.day());
		assertEquals(6,trinta5463.month());
		
		CalendarDate trinta5462 = new CalendarDate(3,9,2000);
		trinta5462.adicionaDia();
		assertEquals(4,trinta5462.day());
		assertEquals(9,trinta5462.month());
		
		CalendarDate trinta5466 = new CalendarDate(3,1,2000);
		trinta5466.adicionaDia();
		assertEquals(4,trinta5466.day());
		assertEquals(1,trinta5466.month());
		
		CalendarDate trinta54667 = new CalendarDate(29,11,2000);
		trinta54667.adicionaDia();
		assertEquals(30,trinta54667.day());
		assertEquals(11,trinta54667.month());
		
		CalendarDate trinta5267 = new CalendarDate(6,3,2000);
		trinta5267.adicionaDia();
		assertEquals(7,trinta5267.day());
		assertEquals(3,trinta5267.month());
		
		CalendarDate trinta5767 = new CalendarDate(6,5,2000);
		trinta5767.adicionaDia();
		assertEquals(7,trinta5767.day());
		assertEquals(5,trinta5767.month());
		
		CalendarDate trinta58967 = new CalendarDate(6,7,2000);
		trinta58967.adicionaDia();
		assertEquals(7,trinta58967.day());
		assertEquals(7,trinta58967.month());
		
		CalendarDate trinta656 = new CalendarDate(6,8,2000);
		trinta656.adicionaDia();
		assertEquals(7,trinta656.day());
		assertEquals(8,trinta656.month());
		
		CalendarDate trinta65656 = new CalendarDate(30,10,2000);
		trinta65656.adicionaDia();
		assertEquals(31,trinta65656.day());
		assertEquals(10,trinta65656.month());
		
		CalendarDate trinta655656 = new CalendarDate(31,10,2000);
		trinta655656.adicionaDia();
		assertEquals(1,trinta655656.day());
		assertEquals(11,trinta655656.month());
		
		CalendarDate trinta65536 = new CalendarDate(1,10,2000);
		trinta65536.adicionaDia();
		assertEquals(2,trinta65536.day());
		assertEquals(10,trinta65536.month());
	}

	@Test
	public void testDataDentroParametros() {
		assertTrue(d1.dataDentroParametros());

		
		CalendarDate a = new CalendarDate(-1,16,1800);
		assertFalse(a.dataDentroParametros());
	
		
		CalendarDate b= new CalendarDate(34,0,100000);
		assertFalse(b.dataDentroParametros());
		
		CalendarDate c = new CalendarDate(46,31,1800);
		assertFalse(c.dataDentroParametros());
	
		
		CalendarDate d= new CalendarDate(-1,-2,100000);
		assertFalse(d.dataDentroParametros());
		

	}

	@Test
	public void testDataInicializada() {
		CalendarDate a = new CalendarDate();
		assertTrue(a.dataInicializada(a));
		
		CalendarDate b = null;
		assertFalse(a.dataInicializada(b));
	}

	@Test
	public void testInit() {
		CalendarDate b = new CalendarDate();
		b.init(1, 4, 1995);
		
		assertEquals(1,b.day());
		assertEquals(4,b.month());
		assertEquals(1995,b.year());
	}

	@Test
	public void testInitS() {
		CalendarDate b = new CalendarDate();
		b.initS("01-04-1995");
		
		assertEquals(1,b.day());
		assertEquals(4,b.month());
		assertEquals(1995,b.year());
	}

	@Test
	public void testIsAfter() {
	assertTrue(d2.isAfter(d1));
	assertFalse(d1.isAfter(d2));
	
	CalendarDate d3 = new CalendarDate(5,3,1990);
	assertTrue(d3.isAfter(d1));
	
	CalendarDate d4 = new CalendarDate(6,4,1990);
	assertTrue(d4.isAfter(d3));
	
	CalendarDate d5 = new CalendarDate(10,4,1990);
	assertFalse(d4.isAfter(d5));
	
	CalendarDate d6 = new CalendarDate(10,5,1990);
	assertFalse(d3.isAfter(d6));
	
	}

	@Test
	public void testIsBefore() {
		assertTrue(d1.isBefore(d2));
		assertFalse(d2.isBefore(d1));
		
		CalendarDate d3 = new CalendarDate(5,3,1990);
		assertFalse(d3.isBefore(d1));
		
		CalendarDate d4 = new CalendarDate(6,4,1990);
		assertFalse(d4.isBefore(d3));
		
		CalendarDate d5 = new CalendarDate(10,4,1990);
		assertTrue(d4.isBefore(d5));
		
		CalendarDate d6 = new CalendarDate(10,5,1990);
		assertTrue(d3.isBefore(d6));
	}



	@Test
	public void testIsEqual() {
		CalendarDate b = new CalendarDate();
		b.init(1, 3, 1990);
		
		assertTrue(d1.isEqual(b));
		assertFalse(d1.isEqual(d2));
		
		d1=new CalendarDate(23, 4, 2009);
		d2=new CalendarDate(23, 4, 2009);
		assertTrue("CalendarDate.isEqual()",d1.isEqual(d2));

		d2.destroy();
		d2=new CalendarDate(24, 4, 2009);
		assertFalse("CalendarDate.isEqual()",d1.isEqual(d2));
		d2.destroy();
		d2=new CalendarDate(23, 5, 2009);
		assertFalse("CalendarDate.isEqual()",d1.isEqual(d2));
		d2.destroy();
		d2=new CalendarDate(23, 4, 2010);
		assertFalse("CalendarDate.isEqual()",d1.isEqual(d2));
	}

	

	@Test
	public void testIsLeap() {
		assertFalse(d1.isLeap());
		
		assertTrue(d2.isLeap());
		
		CalendarDate d3 = new CalendarDate(1,1,2000);
		assertTrue(d3.isLeap());
		
		CalendarDate d4 = new CalendarDate(1,5,1900);
		assertFalse(d4.isLeap());
		
	}

	@Test
	public void testStringToDate() {
		CalendarDate cd = new CalendarDate();
		cd.stringToDate("01-04-1994");
		
		CalendarDate cd2 = new CalendarDate();
		cd2.stringToDate("01-03-1990");
		
		CalendarDate cd3 = new CalendarDate();
		cd3.stringToDate("01-03-2011");
	}

	@Test
	public void testYearsSince() {
		assertEquals(22,d2.yearsSince(d1));
		
		CalendarDate d4 = new CalendarDate(29,4,1990);
		
		CalendarDate d6 = new CalendarDate(30,4,1990);
		assertEquals(-1,d4.yearsSince(d6));
		
		d1=new CalendarDate(23, 3, 2010);
		d2=new CalendarDate(24, 4, 2008);
		assertEquals(1,d1.yearsSince(d2));
		
		d1=new CalendarDate(23, 3, 2010);
		d2=new CalendarDate(24, 4, 2008);
		assertEquals(1,d1.yearsSince(d2));
		
		d1=new CalendarDate(23, 4, 2010);
		d2=new CalendarDate(24, 4, 2008);
		assertEquals(1,d1.yearsSince(d2));
		
		d1=new CalendarDate(24, 4, 2010);
		d2=new CalendarDate(23, 4, 2008);
		assertEquals(2,d1.yearsSince(d2));
		
		d1=new CalendarDate(24, 4, 2010);
		d2=new CalendarDate(2, 6, 2008);
		assertEquals(2,d1.yearsSince(d2));
		


	}

}
